package com.wavehi.producer;

import com.rabbitmq.client.Channel;
import com.wavehi.util.RabbitMQFactoryUtils;

import java.util.Scanner;

/**
 * @Description 生成者 演示预取值分发
 * @Author WaveHi
 * @Date 26/12/2021 下午 7:18
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 */
public class Producer_03 {

    //队列名
    private static final String QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws Exception {
        //1.获取连接信道
        Channel channel = RabbitMQFactoryUtils.getChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //2.准备消息
        Scanner scanner = new Scanner(System.in);
        String message = null;
        //3.发送消息
        while(scanner.hasNext()) {
            message = scanner.next();
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
            System.out.println("Send message '" + message + "'");
        }
    }
}
